package com.sw.paisong.util;

import org.apache.commons.lang3.StringUtils;

import com.sw.paisong.vo.FormVO;
import com.sw.paisong.vo.JsonVO;

public class FormUtils {
	public static final String ACTION_TYPE_ADD = "add";
	public static final String ACTION_TYPE_ALTER = "alter";
	public static final String ERROR_WORD_PARAMS_MISS = "缺少请求参数";
	public static final String ERROR_WORD_PARAMS_EXCEPTION="请求参数异常";

	public static JsonVO formVaild(FormVO formVO) {
		boolean isSuccess = true;
		String message = "";
		if (formVO == null) {
			isSuccess = false;
			message = ERROR_WORD_PARAMS_MISS;
		}
		if (isSuccess) {
			if (StringUtils.isBlank(formVO.getActionType())) {
				isSuccess = false;
				message = ERROR_WORD_PARAMS_MISS;
			} else {
				if (!formVO.getActionType().equals(ACTION_TYPE_ADD)
						&& !formVO.getActionType().equals(ACTION_TYPE_ALTER)) {
					isSuccess = false;
					message = ERROR_WORD_PARAMS_EXCEPTION;
				}
			}
		}
		JsonVO json = new JsonVO();
		json.setSuccess(isSuccess);
		json.setMessage(message);
		return json;
	}
}
